﻿using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace MetaSharp.Transformation.Tests.Patterns
{
    public class TransformTests
    {
        [Fact]
        public async Task TransformRuleHasImplicitErrorUntil()
        {
            var p = Pattern.Transform(Pattern.Value('a'));
            var m = await Pattern.Match(p, "zzzz");
            var e = m.Errors.Single();
            Assert.Equal(SourceSpan.From(0, 4), e.Span);
        }
        
        [Fact]
        public async Task PatternWillNotMatchIfStreamIsNotFullyRead()
        {
            var p = Pattern.Transform(Pattern.Value('a'));
            var m = await Pattern.Match(p, "aa");
            Assert.False(m.Matched);
        }

        [Fact]
        public async Task NotReadingToEndOfStreamProducesAndError()
        {
            var p = Pattern.Transform(Pattern.Value('a'));
            var m = await Pattern.Match(p, "aa");
            var e = m.Errors.Single();
            Assert.Equal(SourceSpan.From(1, 2), e.Span);
        }
    }
}
